<template>
  <div class="linliao">
    <h1
      style="
        font-weight: 700;
        font-style: normal;
        font-size: 24px;
        color: #344563;
        margin-bottom: 20px;
      "
    >
      部门领料
    </h1>
    <div style="display: flex">
      <div class="block">
        <span class="demonstration">开始时间</span>
        <el-date-picker
          v-model="value1"
          type="datetime"
          placeholder="选择日期时间"
          default-time="12:00:00"
        >
        </el-date-picker>
      </div>
      <div class="block" style="margin-left: 50px">
        <span class="demonstration">结束时间</span>
        <el-date-picker
          v-model="value2"
          type="datetime"
          placeholder="选择日期时间"
          default-time="12:00:00"
        >
        </el-date-picker>
      </div>
      <el-row>
        <el-button
          style="margin-left: 20px"
          type="primary"
          icon="el-icon-zoom-in"
          size="mediu"
          @click="queryData"
          >查询</el-button
        >
        <el-button type="success" icon="el-icon-plus" size="mediu" @click="fn"
          >新增</el-button
        >
        <el-button type="info" icon="el-icon-refresh-right" size="mediu"
          >重置</el-button
        >
      </el-row>
    </div>

    <div id="box">
      <el-form
        ref="form"
        :model="form"
        label-width="80px"
        style="display: flex"
      >
        <el-form-item label="领用部门">
          <el-select v-model="form.region" placeholder="维修三部">
            <el-option label="全部" value="shanghai"></el-option>
            <el-option label="维修一部" value="beijinga"></el-option>
            <el-option label="维修二部" value="beijingb"></el-option>
            <el-option label="维修三部" value="beijingc"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="审核状态" id="boxA">
          <el-select v-model="form.state" placeholder="待审核">
            <el-option label="全部" value="shanghai"></el-option>
            <el-option label="待审核" value="beijing"></el-option>
            <el-option label="审核通过" value="beijing"></el-option>
            <el-option label="审核拒绝" value="beijing"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="搜索">
          <el-input v-model="form.dan" placeholder="亲输入领料单号"></el-input>
        </el-form-item>
      </el-form>
    </div>
    <el-table
      ref="multipleTable"
      :data="tableData"
      tooltip-effect="dark"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column prop="pickingDate" label="领料日期" width="120">
      </el-table-column>
      <el-table-column prop="pickingNo" label="领料单号" width="120">
      </el-table-column>
      <el-table-column prop="personalDept" label="领料部门"> </el-table-column>
      <el-table-column prop="preparedBy" label="制单人"> </el-table-column>
      <el-table-column prop="auditStatus" label="审核状态"> </el-table-column>
      <el-table-column prop="reviewedBy" label="审核人"> </el-table-column>
      <el-table-column prop="id" label="操作">
        <template template scope="scope">
          <el-button
            size="small"
            class="edit_btn"
            type="primary"
            icon="el-icon-edit-outline"
            @click="fna"
          >
          </el-button>
          <el-button
            class="del_btn"
            type="primary"
            icon="el-icon-delete"
            size="small"
            @click="open(scope.row.pickingNo)"
          >
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <div class="block">
      <span class="demonstration">直接前往</span>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page.sync="currentPage3"
        :page-size="limit"
        layout="prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>
<style scoped>
#boxA {
  position: relative;
  left: 37px;
  top: 0;
}
#box {
  position: relative;
  left: -11px;
  top: 15px;
}
.linliao {
  padding: 30px;
}
.del_btn {
  font-size: 14px;
  color: #ffc5c5;
  background: #fef3f3;
  border-color: #fef3f3;
}

.edit_btn {
  font-size: 14px;
  color: #5fa4e2;
  background: #eef6fc;
  border-color: #eef6fc;
}
.block{
  float:right;
  display: flex;
}
</style>

<script>
export default {
  data() {
    return {
      currentPage3: 5,
      value1: "",
      value2: "",
      form: {
        region: "",
        state: "",
        dan: "",
      },
      tableData: [],
      multipleSelection: [],
      limit: 5,
      page: 1,
      total: 0,
    };
  },
  methods: {
    toggleSelection(rows) {
      if (rows) {
        rows.forEach((row) => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    open(delld) {
      let del_id = delld;
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$axios({
            url: "/WPickingManagement/delete",
            method: "delete",
            params: {
              pickingNo: del_id,
            },
          }).then((res) => {
            if (res.data.code == 0) {
              this.$message({
                type: "success",
                message: "删除成功!",
              });
              this.postData();
            } else {
              this.$message({
                type: "info",
                message: "删除失败！！！",
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.page = val;
      this.postData();
    },
    fn: function () {
      this.$router.push("/home/xzlld");
    },
    fna: function () {
      this.$router.push("/home/Cklld");
    },
    postData: function () {
      this.$axios({
        url: "/WPickingManagement/list",
        method: "post",
        data: {
          limit: 5,
          page: 1,
        },
      }).then((res) => {
        console.log(res.data.data);
        if (res.data.code == 0) {
          this.tableData = res.data.data;
        }
      });
    },
    queryData() {
      this.$axios({
        url: "/WPickingManagement/list",
        method: "post",
        data: {
          limit: 5,
          page: 1,
          pickingNo: this.form.dan,
        },
      }).then((res) => {
        if (res.data.code == 0) {
          this.tableData = res.data.data;
        }
      });
    },
  },
  mounted: function () {
    this.postData();
    this.queryData();
  },
};
</script>